package com.eva.framework.rbac.exception;

import com.eva.framework.common.model.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * RBAC相关全局异常处理
 */
@Slf4j
@Component
@Order(1)
@RestControllerAdvice
public class RbacGlobalExceptionAdvice {

    /**
     * 无权限异常处理
     */
    @ExceptionHandler(UnauthorizedException.class)
    public Object handleUnauthorizedException (UnauthorizedException e) {
        log.error("无权访问");
        return ApiResponse.failed(HttpStatus.FORBIDDEN.value(), "您当前账号没有该权限，请联系管理员授权！");
    }
}
